package com.xue566.util;

import com.xue566.enums.StateEnum;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
public class ResultBody<T> implements Serializable {


    /**
     * @param url : 返回子域名
     * @Author: Wuzh
     * @Description: 成功方法
     * @Data:
     */
    public static ResultBody success (String url) {
        ResultBody resultBody = new ResultBody();
        resultBody.code = StateEnum.SUCCESS.getCode();
        resultBody.message = StateEnum.SUCCESS.getMessage();
        resultBody.url = url;
        return resultBody;
    }

    /**
     * @param url : 返回子域名
     * @Author: Wuzh
     * @Description: 成功方法
     * @Data:
     */
    public static ResultBody success (Object object, String url) {
        ResultBody resultBody = new ResultBody<>();
        resultBody.code = StateEnum.SUCCESS.getCode();
        resultBody.message = StateEnum.SUCCESS.getMessage();
        resultBody.url = url;
        resultBody.totalCount = 1;
        resultBody.queryList.add(object);
        return resultBody;
    }

    /**
     * @param pageNum    : 页码
     * @param pageSize   : 每页数量
     * @param totalCount : 记录总数
     * @param queryList  : 返回数据
     * @param url        : 返回子域名
     * @Author: Wuzh
     * @Description: 成功方法
     * @Data:
     */
    public static ResultBody success (int pageNum, int pageSize, long totalCount, List queryList, String url) {
        ResultBody resultBody = new ResultBody<>();
        resultBody.totalCount = totalCount;
        resultBody.pageNum = pageNum;
        resultBody.pageSize = pageSize;
        resultBody.code = StateEnum.SUCCESS.getCode();
        resultBody.message = StateEnum.SUCCESS.getMessage();
        resultBody.queryList = queryList;
        resultBody.url = url;
        return resultBody;
    }

    /**
     * @param code    : 返回状态码
     * @param message : 返回信息
     * @Author: Wuzh
     * @Description: 异常执行失败方法
     * @Data:
     */
    public static ResultBody fail (String code, String message) {
        ResultBody resultBody = new ResultBody<>();
        resultBody.code = code;
        resultBody.message = message;
        return resultBody;
    }

    /**
     * 查询得到的数据列表
     */
    private List<T> queryList = new ArrayList<T>();

    /**
     * 查询总记录数
     */
    private long totalCount;

    /**
     * 页码
     */
    private int pageNum;

    /**
     * 每页条数
     */
    private int pageSize = 10;

    /**
     * 结果编码，000000表示查询成功
     */
    private String code;

    /**
     * 结果信息
     **/
    private String message;

    /**
     * 返回子域名
     */
    private String url;
}
